<!-- 折叠轮播图 组件-->
<template>
	<view class="swpbig">
		<view class="swiperPanel" ref="swiperPanel" @touchstart="startMove" @touchend="endMove">
			<view class="swiperItem" v-for="(item, index) in swiperList" :key="index"
				:style="{transform: itemStyle[index].transform, zIndex: itemStyle[index].zIndex}">
				<view class="children">
					<view class="pic">
						<image class="pici" :src="item.url" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var timer;
	export default {
		props: {
			swiperList: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				slideNote: {
					x: 0,
					y: 0
				},
				screenWidth: 0,
				itemStyle: []
			};
		},
		created() {
			var macInfo = uni.getSystemInfoSync();
			this.screenWidth = macInfo.screenWidth;
			// 计算swiper样式
			this.swiperList.forEach((item, index) => {
				this.itemStyle.push(this.getStyle(index))
			})
			// timer = setInterval(() => {
			// 	this.rightSlider();
			// }, 3000)
		},
		methods: {
			// 自动轮播效果
			rightSlider() {
				var newList = JSON.parse(JSON.stringify(this.itemStyle));
				var last = [newList.pop()]
				newList = last.concat(newList)
				this.itemStyle = newList;
			},
			getStyle(e) {
				if (e > this.swiperList.length / 2) {
					var right = this.swiperList.length - e
					return {
						transform: 'scale(' + (1 - right / 10) + ') translate(-' + (right * 9) + '%,0px)',
						zIndex: 9999 - right,
						opacity: 0.5 / right
					}
				} else {
					return {
						transform: 'scale(' + (1 - e / 10) + ') translate(' + (e * 9) + '%,0px)',
						zIndex: 9999 - e,
						opacity: 0.5 / e
					}
				}
			},
			startMove(e) {
				clearInterval(timer);
				this.slideNote.x = e.changedTouches[0] ? e.changedTouches[0].pageX : 0;
				this.slideNote.y = e.changedTouches[0] ? e.changedTouches[0].pageY : 0;
			},
			endMove(e) {
				// timer = setInterval(() => {
				// 	this.rightSlider();
				// }, 3000)
				var newList = JSON.parse(JSON.stringify(this.itemStyle));
				if ((e.changedTouches[0].pageX - this.slideNote.x) < 0) {
					// 向左滑动
					var last = [newList.pop()]
					newList = last.concat(newList)
				} else {
					// 向右滑动
					newList.push(newList[0])
					newList.splice(0, 1)
				}
				this.itemStyle = newList
			}
		}
	}
</script>

<style lang="scss">
	.swpbig {
		overflow: hidden;
	}

	.swiperPanel {
		margin-top: 50rpx;
		height: 680rpx;
		width: 686rpx;
		overflow: hidden;
		position: relative;
		margin-left: 80rpx;

		.swiperItem {
			height: 100%;
			width: 100%;
			position: absolute;
			top: 0;
			left: 0rpx;
			transition: all .3s;

			.children {
				// height: 100%;
				width: 570rpx;
				margin: 2rpx 160rpx 2rpx 0;
				position: relative;

				.pic {
					position: relative;
					height: 645rpx;
					width: 560rpx;
					border-radius: 15rpx;
				}

				.pici {
					position: absolute;
					height: 645rpx;
					width: 560rpx;
					border-radius: 15rpx;
				}

				.banner_signal {
					position: absolute;
					height: 645rpx;
					width: 560rpx;
					top: 0;
				}

				.swpnew {
					position: absolute;
					height: 63rpx;
					font-size: 45rpx;
					font-weight: bold;
					color: #FFF;
					line-height: 53rpx;
					right: 28rpx;
					margin-top: 12rpx;
					letter-spacing: 5rpx;
				}
			}
		}
	}
</style>